<template>
  <div>
    <el-card shadow="never" class="aui-card--fill">
      <el-collapse-transition>
        <el-form v-if="searchShow" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
          <!--文本框-->
          <el-form-item>
            <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
          </el-form-item>
          <!--文本框-->
          <el-form-item>
            <el-input v-model="dataForm.userId" placeholder="用户ID" clearable></el-input>
          </el-form-item>
          <!--文本框-->
          <el-form-item>
            <el-input v-model="dataForm.ruleSort" placeholder="权限分类-如DS_DEPT" clearable></el-input>
          </el-form-item>
          <!--文本框-->
          <el-form-item>
            <el-input v-model="dataForm.creator" placeholder="创建者" clearable></el-input>
          </el-form-item>
          <!--日期框-->
          <el-form-item>
            <el-date-picker v-model="dataForm.createDate" placeholder="创建时间" type="date"></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getDataList()">{{ $t('query') }}</el-button>
            <el-button @click="searchReset()">{{ $t('reset') }}</el-button>
          </el-form-item>
        </el-form>
      </el-collapse-transition>
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('sys:sysUserCustrule:save')" type="primary" @click="addOrUpdateHandle()">{{
            $t('add') }}</el-button>
          <el-button v-if="$hasPermission('sys:sysUserCustrule:delete')" type="danger" @click="deleteHandle()">{{
            $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <el-button icon="el-icon-download" @click="$refs.xTable.openExport()" circle></el-button>
        </template>
      </vxe-toolbar>
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize @select-change="dataListSelectionChangeHandleVex"
        @select-all="dataListSelectionAllChangeHandleVex" :data="dataList">
        <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
        <vxe-table-column field="userId" title="用户ID">
        </vxe-table-column>
        <vxe-table-column field="ruleSort" title="权限分类-如DS_DEPT">
        </vxe-table-column>
        <vxe-table-column field="customData" title="自定义数据">
        </vxe-table-column>
        <vxe-table-column field="updater" title="更新者">
        </vxe-table-column>
        <vxe-table-column field="updateDate" title="更新时间">
        </vxe-table-column>
        <vxe-table-column title="handle" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('sys:sysUserCustrule:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('sys:sysUserCustrule:delete')" type="text" size="small" icon="el-icon-delete"
              @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './sysUserCustrule-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/sys/sysUserCustrule/page',
        getDataListIsPage: true,
        deleteURL: '/sys/sysUserCustrule',
        deleteIsBatch: true,
        exportURL: '/sys/sysUserCustrule/export'
      },
      dataForm: {
        id: '',
        userId: '',
        ruleSort: '',
        creator: '',
        createDate: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
